The United Arab Emirates agreed to invest $35 billion in Egypt, a breakthrough in Cairo’s efforts to end its worst foreign-exchange crisis in decades.